package org.jypj.dev.controller;

import org.jypj.dev.dao.ShoesDao;
import org.jypj.dev.model.Shoes;
import org.jypj.dev.util.StringUtil;
import org.jypj.dev.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author ChenYu
 * @date 2017-06-12
 */
@Controller
@RequestMapping("shoes")
public class ShoesController extends BaseController {

    @Resource
    private ShoesDao shoesDao;

    /**
     * 查询所有鞋子
     *
     * @param shoes
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectAll")
    public Result selectShoes(Shoes shoes) {
        Result result = new Result();
        try {
            shoes.setStatus("1");
            List<Shoes> shoes1 = shoesDao.selectAllByShoes(shoes);
            result.getDataMap().put("shoesList", shoes1);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(-1);
        }
        return result;
    }

    /**
     * 查询单个鞋子
     *
     * @param shoes
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectOne")
    public Result selectSingleShoes(Shoes shoes) {
        Result result = new Result();
        try {
            shoes.setStatus("1");
            Shoes shoes1 = shoesDao.selectObjectByShoes(shoes);
            result.getDataMap().put("shoes", shoes1);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(-1);
            result.setMsg("网络异常");
            result.setExcMsg(e.toString());
        }
        return result;
    }
}
